jQuery.fn.mousehold = function(timeout, f) {

	if (timeout && typeof timeout == 'function') {
		f = timeout;
		timeout = 100;
	}
	if (f && typeof f == 'function') {
		var timer = 0;
		var fireStep = 0;
		return this.each(function() {
			jQuery(this).mousedown(function() {
				var my_e;
				$(document).mousemove(function (e){
					my_e = e;
				});
				fireStep = 1;
				var ctr = 0;
				var t = this;
				timer = setInterval(function() {
					ctr++;
					f.call(t, ctr, my_e);
					fireStep = 2;
				}, timeout);
			})

			clearMousehold = function() {
                                $(document).unbind('mousemove');
				clearInterval(timer);
				if (fireStep == 1) f.call(this, 1);
				fireStep = 0;
			}

			jQuery(this).mouseout(clearMousehold);
			jQuery(this).mouseup(clearMousehold);
		})
	}
}